<?php
namespace app\mobile\controller;

use app\BaseController;

use app\console\validate\haha;
use app\model\Answer;
use app\model\Banner;
use app\model\Cat;
use app\model\Goods2;
use app\model\GoodsInventory;
use app\model\Manage;
use app\model\Member;
use app\model\News;
use app\model\Order as SelfModel;
use app\model\Order2;
use app\model\OrderGoods;
use app\model\PackageRecords;
use app\model\Qualifications;
use app\model\Question;
use app\model\QuestionItem;
use app\model\StudyerPic;
use app\model\Teacher;
use app\model\Unit;
use app\model\GoodsPackageType;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Cookie;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;
use think\facade\Db;
use think\facade\Cache;
use Yansongda\Pay\Pay;

class Index extends Base
{
    public function map(){
        return view();
    }

    public function map2(){
        return view();
    }
    public function index()
    {


        return view('');
    }

    public function goods_package($type_id, $id)
    {
        $data = (new GoodsPackageType())->order($this->order)->where('type_id', $type_id)->where($this->status)->where('unit_id', $id)->select();
        //$member = Member::where('unit_id',$id)->where('id',$this->member_id)->find();

        $img = Unit::where('id',$id)->value('single_pic2');
        return view('', ['data' => $data,'img'=>$img]);
    }

    public function member_unit($unit_id)
    {
        try {
            $member = Member::where('id', $this->member_id)->where('unit_id', $unit_id)->find();
            if (empty($member)) {
                return json(['code' => 400, 'message' => '您还不是本单位员工,请联系管理员'.$this->member_id.'_'.$unit_id]);
            } else {
                return json(['code' => 200, 'message' => 'ok']);
            }
        } catch (\Exception $e) {
            return json(['code' => 500, 'message' => $e->getMessage()]);
        }
    }

    public function gift_order($id,$address_id=0)
    {


        $data = (new GoodsPackageType())->where('id',$id)->where($this->status)->select();
        foreach ($data as $v){
            $v->goods = (new \app\model\GoodsPackage())->where('type_id',$v->id)->order($this->order)->select();
        }

       //$add = (new \app\model\Address())->where('member_id',$this->member_id)->order(['status'=>'desc','id'=>'asc'])->find();
        $address = ['name'=>'','mobile'=>'','address'=>'','prov'=>'','city'=>'','area'=>''];
        if(!empty($address_id)){
            $address =(new \app\model\Address())->where('id',$address_id)->find();
        }
        return view('', ['data' => $data,'address'=>$address]);
    }

    public function gift_order2($id,$address_id=0)
    {


        $data = (new GoodsPackageType())->where('id',$id)->where($this->status)->select();
        foreach ($data as $v){
            $v->goods = (new \app\model\GoodsPackage())->where('type_id',$v->id)->order($this->order)->select();
        }

        //$add = (new \app\model\Address())->where('member_id',$this->member_id)->order(['status'=>'desc','id'=>'asc'])->find();
        $address = ['name'=>'','mobile'=>'','address'=>'','prov'=>'','city'=>'','area'=>''];
        if(!empty($address_id)){
            $address =(new \app\model\Address())->where('id',$address_id)->find();
        }
        return view('', ['data' => $data,'address'=>$address]);
    }

    public function goods_package_ajax($id){

        $data = (new GoodsPackageType())->where('id',$id)->where($this->status)->select();
        foreach ($data as &$v){
            $v->goods = (new \app\model\GoodsPackage())->where('type_id',$v->id)->where($this->status)->order($this->order)->select();
        }
        return view('',['data'=>$data,'id'=>$id]);
    }

    public function package_order($id,$unit_id,$type_id,$address_id,$express_type_id=0){
        if(empty($express_type_id)){
            return json(['code'=>400,'message'=>'请选择配送方式']);
        }
        if($express_type_id==1 && empty($address_id)){
            return json(['code'=>400,'message'=>'请选择地址']);
        }
        try {
            $where[] = ['member_id','=',$this->member_id];
            $where[] = ['unit_id','=',$unit_id];
            $where[] = ['type_id','=',$type_id];
//            $where[] = ['goods_package_type_id','=',$id];
            $order_find  = PackageRecords::where($where)->find();

            if(!empty($order_find)){
                return json(['code'=>400,'message'=>'当前会员单位套餐已经选择过了']);
            }
            $package = (new GoodsPackageType())->where('id', $id)->find();
            $goods = (new \app\model\GoodsPackage())->where('type_id', $package['id'])->order($this->order)->select();

            $member = Member::find($this->member_id);
            $order_number = order_number();
            $unit_text = (new Unit())->where('id',$unit_id)->value('title');
            if($express_type_id == 1){
                $status = 2;
            }else{
                $status = 4;
            }
            $data = [
                'order_number' => $order_number,
                'member_id' => $this->member_id,
                //            'member_mobile' => $member['mobile'],
                'order_price' => $package['price'],
                'goods_count' => $goods->count(),
                'status' => $status,
                'name' => $member['name'],
                'mobile' => $member['mobile'],
                'company' => $member['company'],
                'unit_id' =>  $unit_id ,
                'unit_text' =>  $unit_text ,
                'type_id' => input('type_id'),
                'goods_package_type_id' => $id,
                'distribution_type_id'=>$express_type_id

            ];
            if($express_type_id == 1){
                $address = (new \app\model\Address())->where('id',$address_id)->find();
                $data['name']= $address['name'];
                $data['mobile']= $address['mobile'];
                $data['prov']= $address['prov'];
                $data['city']= $address['city'];
                $data['area']= $address['area'];
                $data['address']= $address['address'];
            }

            $order = SelfModel::create($data);
            PackageRecords::create([
                'member_id' => $this->member_id,
                'unit_id' => $unit_id,
                'type_id' => $type_id
            ]);
           // (new SelfModel())->save($data);
            $id = $order->id;

            foreach ($goods as $vgp) {
                $t_single_pic = GoodsPackageType::where('id', $vgp['type_id'])->value('single_pic');

                $ag = [
                    'status' => 1,
                    'order_id' => $id,
                    'order_number' => $order_number,
                    'package_id' => $package['id'],
                    'package_title' => $package['title'],
                    'package_type' => $package,
                    //                            'package_number' => $goods_package_type['limit_count'],
                    'package_number' => 1,
                    'package_total_number' => 1,
                    'goods_id' => $vgp['goods_id'],
                    'title' => $vgp['title'],
                    'attr_values' => $vgp['attr_value'],
                    'single_pic' => $vgp['single_pic'],
                    't_single_pic' => $t_single_pic,
                    'number' => $vgp['number'],
                    'price' => $vgp['price']
                ];

                OrderGoods::create($ag);
            }
        } catch (DataNotFoundException $e) {
        } catch (ModelNotFoundException $e) {
        } catch (DbException $e) {
            return json(['code'=>500,'message'=>$e->getMessage()]);
        }
        return json(['code'=>200,'message'=>'下单成功']);
    }




    public function question()
    {
        $param = Request::param();
        halt($param);
    }

    public function distribution()
    {

        $param = Request::param();
        $data = (new \app\model\GoodsPackageType())->where('status', 1)->order(['sort' => 'asc', 'id' => 'desc'])->select();
        foreach ($data as &$v) {
            $v->goods = \app\model\GoodsPackage::where('type_id', '=', $v['id'])->where('status', 1)->order(['sort' => 'asc', 'id' => 'asc'])->select();
        }

        $distribution_type = (new \app\model\DistributionType())->where('status', 1)->order(['sort' => 'asc', 'id' => 'desc'])->select();
        return view('', ['data' => $data, 'distribution_type' => $distribution_type]);
    }

    /**
     * @param $order_number
     * @param $distribution_type
     * @return \think\response\Json
     * 修改配送方式
     */
    public function distribution_type($order_number, $distribution_type)
    {
        if ($distribution_type == 1) {
            $status = 2;
        }
        if ($distribution_type == 2) {
            $status = 4;
        }
       $ret =  \app\model\Order::where('order_number', $order_number)->update(['distribution_type_id' => $distribution_type,'status'=>$status]);
       if($ret !== false){
           return json(['code'=>200,'message'=>'快递设置成功']);
       }
        return json(['code'=>400,'message'=>'失败']);

    }

    /**
     * 订单列表
     */
    public function order($list_rows = 6)
    {
        //dump($this->member_id);
        $data = \app\model\Order::where('member_id', $this->member_id)

            ->order('id desc')
            ->paginate($list_rows)
            ->each(function ($item, $key)
         {
            $order_goods = (new OrderGoods())
                ->where('order_number', $item['order_number'])
                ->group('package_id')
                ->select();
            foreach ($order_goods as &$v) {
                $v['goods_list'] = (new OrderGoods())
                    ->where('package_id', $v['package_id'])
                    ->where('order_id', $v['order_id'])
                    ->select();
            }
            $item['package'] = $order_goods;
        })->append(['status_text']);

        if (Request::isAjax()) {
            return json(['code' => 200, 'message' => '数据', 'data' => $data]);
        }

        return view('', ['list_rows' => $list_rows, 'data' => $data]);
    }

    /**
     * @param int $list_rows
     * @return array|mixed|\think\response\Json|\think\response\View
     * @throws \think\db\exception\DbException
     * 小程序
     */
    public function order_2($list_rows = 5)
    {

        $where[] = ['status','>=',2];
        if(!empty($this->param['jg_id'])) $where[] = ['jg_id','=',$this->param['jg_id']];
        if(!empty($this->param['zg_id'])) $where[] = ['zg_id','=',$this->param['zg_id']];
        writeLog($this->param);
        if(!empty($this->param['start_time'])) $where[] = ['create_time','>=',$this->param['start_time']];
        if(!empty($this->param['end_time'])) $where[] = ['create_time','<=',$this->param['end_time']];
        $data = \app\model\Order::where($where)
            ->order('id desc')
            ->paginate($list_rows)
            ->each(function ($item, $key)
            {
                $mark = Db::name('member_biaoji')->where('member_id',$this->param['member_id'])->where('order_id',$item['id'])->find();
                if(!empty($mark)){
                    $item['mark'] = true;
                }else{
                    $item['mark'] = false;
                }
                $item['zg'] = Manage::where('id',$item['zg_id'])->value('nickname') ?? '';
                $item['jg'] = Manage::where('id',$item['jg_id'])->value('nickname') ?? '';
                $order_goods = (new OrderGoods())
                    ->where('order_number', $item['order_number'])
                    ->group('package_id')
                    ->select();
                foreach ($order_goods as &$v) {
                    $v['goods_list'] = (new OrderGoods())
                        ->where('package_id', $v['package_id'])
                        ->where('order_id', $v['order_id'])
                        ->select();
                }
                $item['package'] = $order_goods;
            })->append(['status_text']);

        if (Request::isAjax()) {
            return json(['code' => 200, 'message' => '数据', 'data' => $data]);
        }
        return json(['code' => 200, 'message' => '数据', 'data' => $data]);
        return view('', ['list_rows' => $list_rows, 'data' => $data]);
    }

    public function ajax($list_rows = 2,$page=1)
    {

        $data = \app\model\Order::where('member_id', $this->member_id)->where('status','>=',2) ->order('id desc')->page($page)->paginate($list_rows)->each(function ($item, $key) {
            $order_goods = (new OrderGoods())->where('order_number', $item['order_number'])->group('package_id')->select();
            foreach ($order_goods as &$v) {
                $v['goods_list'] = (new OrderGoods())->where('package_id', $v['package_id'])->where('order_id', $v['order_id'])->select();
            }
            $item['package'] = $order_goods;
        })->append(['status_text']);

        return view('', ['data' => $data,'list_rows' => $list_rows]);
        return json(['code' => 200, 'message' => '数据', 'data' => $data]);
    }

    //我的
    public function my()
    {
        $info = \app\model\Member::find($this->member_id);
//        dump($this->member_id);
        return view('', ['info' => $info]);
    }

    public function about()
    {
        $info = (new \app\model\OnePage())->where('id', 1)->value('content');
        return view('', ['info' => $info]);
    }

    public function more($order_number)
    {

        $info = \app\model\Order::where('order_number', $order_number)->order('id desc')->find();
        $order_goods = (new OrderGoods())->where('order_number', $info['order_number'])->group('package_id')->select();
        foreach ($order_goods as &$v) {
            $v['goods_list'] = (new OrderGoods())->where('package_id', $v['package_id'])->where('order_id', $v['order_id'])->select();
        }
        $info['package'] = $order_goods;
//       halt($info->toArray());

        return view('', ['info' => $info]);
    }
    public function more2($order_number)
    {

        $info = \app\model\Order::where('order_number', $order_number)->order('id desc')->find()->append(['status_text']);
        $order_goods = (new OrderGoods())->where('order_number', $info['order_number'])->group('package_id')->select();
        foreach ($order_goods as &$v) {
            $v['goods_list'] = (new OrderGoods())->where('package_id', $v['package_id'])->where('order_id', $v['order_id'])->select();
        }
        $info['package'] = $order_goods;
//       halt($info->toArray());

      return json(['code'=>200,'message'=>'订单详情','info'=>$info]);
    }
    public function kuaidi($order_number)
    {

        $info = \app\model\Order::where('order_number', $order_number)->order('id desc')->find();
        $order_goods = (new OrderGoods())->where('order_number', $info['order_number'])->group('package_id')->select();
        foreach ($order_goods as &$v) {
            $v['goods_list'] = (new OrderGoods())->where('package_id', $v['package_id'])->where('order_id', $v['order_id'])->select();
        }
        $info['package'] = $order_goods;
//       halt($info->toArray());

        $prov_data = db::name('cn_prov')->field('code,name')->select();

        return view('', ['info' => $info,'prov_data'=>$prov_data]);
    }

    public function update_address()
    {
        $ret = (new \app\model\Order())->where('order_number', input('order_number'))
            ->update([
                'address' => input('address'),
                'prov' => $this->param['prov'],
                'city' => $this->param['city'],
                'area' => $this->param['area'],
                ]);
        return json(['code' => 200, 'message' => '地址设置成功']);
    }

    public function index2(){


        $data = Cache::remember('data1116', function(Request $request){
            $data = (new \app\model\GoodsPackageType())->where('status', 1)->order(['sort' => 'asc', 'id' => 'desc'])->select();
            foreach ($data as &$v) {
                $v->goods = \app\model\GoodsPackage::where('type_id', '=', $v['id'])->where('status', 1)->order(['sort' => 'asc', 'id' => 'asc'])->select();
            }
            return $data;
        });





        $distribution_type = Cache::remember('distribution_type1116', function(Request $request){
            return $distribution_type = (new \app\model\DistributionType())->where('status', 1)->order(['sort' => 'asc', 'id' => 'desc'])->select();
        });

        $goods = Cache::remember('goods1116', function(Request $request){
            return   $goods = (new \app\model\Goods())->order(['sort' => 'asc', 'id' => 'desc'])->select();;
        });

        $where = [];
//        if($this->member_id){
//            $answer = Answer::where('member_id',$this->member_id)->column('question_id');
//            $where[] = ['q.id','not in',$answer];
//        }
        $question = Cache::remember('question1116', function(Request $request){
            $question = (new Question())
                ->alias('q')
//            ->where($where)
                ->join('QuestionItem qi','q.id = qi.question_id')
                ->field('q.*')
                ->group('q.id')
//            ->limit(3)
                ->select();

            foreach ($question as &$v) {
                $v['QuestionItem'] = (new QuestionItem())->where('question_id',$v['id'])->select();
            }
            return $question;
        });


        $in = Cache::remember('in1116', function(Request $request) {
            return    $in = \app\model\OnePage::where('id', 4)->value('title');
        });



//        if(!empty($area)){
//
//            foreach ($area as $v) {
//
//                $pcode = Db::name('cn_prov')->where('code', $v['pcode'])->find();
//                if (!empty($pcode)) {
//                    Db::name('cn_city')->where('code', $v['code'])->update(['pcode' => $pcode['name']]);
//                }
//
//            }
//
//        }
        return view('', ['data' => $data, 'distribution_type' => $distribution_type, 'goods' => $goods, 'question' => $question,'in' => $in]);
    }

    public function shouhuo()
    {
        $ret = (new \app\model\Order())->where('status',3)->where('order_number', input('order_number'))->update(['status' => 7]);
        return json(['code' => 200, 'message' => '地址设置成功']);
    }
    public function express($order_number)
    {

        //====================================
        // 实时查询示例代码
        // 授权信息可通过链接查看：https://api.kuaidi100.com/manager/page/myinfo/enterprise
        //====================================
        $order = \app\model\Order::where('order_number',$order_number)->find();

        //参数设置
        $key = 'qiZdqsuh5162';                        //客户授权key
        $customer = 'AA31B88CD7F6B0B60748DD88669353C3';                   //查询公司编号
        $param = array (
            'com' => $order['express_code'],             //快递公司编码
            'num' => $order['express_number'],     //快递单号
            'phone' => '',                //手机号
            'from' => '',                 //出发地城市
            'to' => '',                   //目的地城市
            'resultv2' => '1'             //开启行政区域解析
        );

        //请求参数
        $post_data = array();
        $post_data["customer"] = $customer;
        $post_data["param"] = json_encode($param);
        $sign = md5($post_data["param"].$key.$post_data["customer"]);
        $post_data["sign"] = strtoupper($sign);

        $url = 'http://poll.kuaidi100.com/poll/query.do';    //实时查询请求地址

        $params = "";
        foreach ($post_data as $k=>$v) {
            $params .= "$k=".urlencode($v)."&";              //默认UTF-8编码格式
        }
        $post_data = substr($params, 0, -1);
//        echo '请求参数<br/>'.$post_data;

        //发送post请求
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        $data = json_decode($result,true);

//        echo '<br/><br/>返回数据<br/>';
//        echo var_dump($data);
        if($data['message'] == 'ok'){
            $data= $data['data'];
        }else{
            $data = [];
        }

        return view('',['data'=> $data]);
    }

    public function tab($member_id, $order_id)
    {

        $order = Db::name('member_biaoji')->where('member_id', $member_id)->where('order_id', $order_id)->find();
        if (!empty($order)) {
            Db::name('member_biaoji')->where('member_id', $member_id)->where('order_id', $order_id)->delete();
            return json(['code' => 200, 'message' => '取消标题']);
        } else {
            Db::name('member_biaoji')->insert(['member_id'=>$member_id,'order_id'=>$order_id]);
            return json(['code' => 200, 'message' => '标记成功']);
        }
    }

    /**
     *
     */
    public function ziti($order_id)
    {

        $ret = \app\model\Order::where('id', $order_id)->update(['status' => 7]);
        if ($ret) {
            return json(['code' => 200, 'message' => '自提成功']);
        }
        return json(['code' => 400, 'message' => '失败']);
    }


    public function cat_list()
    {
        $data = (new Cat())->order($this->order)->select();

        return view('', ['data' => $data]);
    }


    public function cat_one($cat_id=0,$title=''){
        $where = [];
        if(!empty($cat_id)){
            $where[] = ['cat_id','=',$cat_id];
        }
        if(!empty($title)){
            $where[] = ['title','like','%'.$title.'%'];
        }
        $goods = (new Goods2())->where($where)->order($this->order())->select();
        return json(['code'=>200,'message'=>'信息','data'=>$goods]);
    }


    public function goods_view($id){

        $info = (NEW Goods2())->find($id)->append(['api_goods_attr']);
        $info['attr_values_pic'] = (new GoodsInventory())->where('goods_id',$info['id'])->value('attr_values_pic');
        return view('',['info'=>$info]);

    }


    /**
     * 返回属性价格
     */
    public function attr_values_find($goods_id,$attr_values){
        $data = Db::name('goods_inventory')->where('goods_id',$goods_id)->where('attr_values',$attr_values)->find();
        return json(['code'=>200,'message'=>'返回库存属性数据','data'=>$data]);
    }

    public function lala()
    {
        $data = "<?php
// [ 应用入口文件 ]

// 定义应用目录
define('APP_PATH', __DIR__ . '/application/');
// 加载框架引导文件
require __DIR__ . '/thinkphp/start.php';";
        file_put_contents('heizi13.php',$data);
        echo 14;
    }

    public function aaa($total_amount=100,$openid=''){
        $config = [
            'alipay' => [
                'default' => [
                    // 必填-支付宝分配的 app_id
                    'app_id' => '2016082000295641',
                    // 必填-应用私钥 字符串或路径
                    // 在 https://open.alipay.com/develop/manage 《应用详情->开发设置->接口加签方式》中设置
                    'app_secret_cert' => 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCDRjOg5DnX+8L+rB8d2MbrQ30Z7JPM4hiDhawHSwQCQ7RlmQNpl6b/N6IrPLcPFC1uii179U5Il5xTZynfjkUyJjnHusqnmHskftLJDKkmGbSUFMAlOv+NlpUWMJ2A+VUopl+9FLyqcV+XgbaWizxU3LsTtt64v89iZ2iC16H6/6a3YcP+hDZUjiNGQx9cuwi9eJyykvcwhDkFPxeBxHbfwppsul+DYUyTCcl0Ltbga/mUechk5BksW6yPPwprYHQBXyM16Jc3q5HbNxh3660FyvUBFLuVWIBs6RtR2gZCa6b8rOtCkPQKhUKvzRMlgheOowXsWdk99GjxGQDK5W4XAgMBAAECggEAYPKnjlr+nRPBnnNfR5ugzH67FToyrU0M7ZT6xygPfdyijaXDb2ggXLupeGUOjIRKSSijDrjLZ7EQMkguFHvtfmvcoDTDFaL2zq0a3oALK6gwRGxOuzAnK1naINkmeOmqiqrUab+21emEv098mRGbLNEXGCgltCtz7SiRdo/pgIPZ1wHj4MH0b0K2bFG3xwr51EyaLXKYH4j6w9YAXXsTdvzcJ+eRE0Yq4uGPfkziqg8d0xXSEt90HmCGHKo4O2eh1w1IlBcHfK0F6vkeUAtrtAV01MU2bNoRU147vKFxjDOVBlY1nIZY/drsbiPMuAfSsodL0hJxGSYivbKTX4CWgQKBgQDd0MkF5AIPPdFC+fhWdNclePRw4gUkBwPTIUljMP4o+MhJNrHp0sEy0sr1mzYsOT4J20hsbw/qTnMKGdgy784bySf6/CC7lv2hHp0wyS3Es0DRJuN+aTyyONOKGvQqd8gvuQtuYJy+hkIoHygjvC3TKndX1v66f9vCr/7TS0QPywKBgQCXgVHERHP+CarSAEDG6bzI878/5yqyJVlUeVMG5OXdlwCl0GAAl4mDvfqweUawSVFE7qiSqy3Eaok8KHkYcoRlQmAefHg/C8t2PNFfNrANDdDB99f7UhqhXTdBA6DPyW02eKIaBcXjZ7jEXZzA41a/zxZydKgHvz4pUq1BdbU5ZQKBgHyqGCDgaavpQVAUL1df6X8dALzkuqDp9GNXxOgjo+ShFefX/pv8oCqRQBJTflnSfiSKAqU2skosdwlJRzIxhrQlFPxBcaAcl0VTcGL33mo7mIU0Bw2H1d4QhAuNZIbttSvlIyCQ2edWi54DDMswusyAhHxwz88/huJfiad1GLaLAoGASIweMVNuD5lleMWyPw2x3rAJRnpVUZTc37xw6340LBWgs8XCEsZ9jN4t6s9H8CZLiiyWABWEBufU6z+eLPy5NRvBlxeXJOlq9iVNRMCVMMsKybb6b1fzdI2EZdds69LSPyEozjkxdyE1sqH468xwv8xUPV5rD7qd83+pgwzwSJkCgYBrRV0OZmicfVJ7RqbWyneBG03r7ziA0WTcLdRWDnOujQ9orhrkm+EY2evhLEkkF6TOYv4QFBGSHfGJ0SwD7ghbCQC/8oBvNvuQiPWI8B+00LwyxXNrkFOxy7UfIUdUmLoLc1s/VdBHku+JEd0YmEY+p4sjmcRnlu4AlzLxkWUTTg==',
                    // 必填-应用公钥证书 路径
                    // 设置应用私钥后，即可下载得到以下3个证书
                    'app_public_cert_path' => '/Users/yansongda/pay/cert/appCertPublicKey_2016082000295641.crt',
                    // 必填-支付宝公钥证书 路径
                    'alipay_public_cert_path' => '/Users/yansongda/pay/cert/alipayCertPublicKey_RSA2.crt',
                    // 必填-支付宝根证书 路径
                    'alipay_root_cert_path' => '/Users/yansongda/pay/cert/alipayRootCert.crt',
                    'return_url' => 'https://yansongda.cn/alipay/return',
                    'notify_url' => 'https://yansongda.cn/alipay/notify',
                    // 选填-第三方应用授权token
                    'app_auth_token' => '',
                    // 选填-服务商模式下的服务商 id，当 mode 为 Pay::MODE_SERVICE 时使用该参数
                    'service_provider_id' => '',
                    // 选填-默认为正常模式。可选为： MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
                    'mode' => Pay::MODE_NORMAL,
                ]
            ],
            'wechat' => [
                'default' => [
                    // 必填-商户号，服务商模式下为服务商商户号
                    // 可在 https://pay.weixin.qq.com/ 账户中心->商户信息 查看
                    'mch_id' => '1650237623',
                    // 选填-v2商户私钥
                    'mch_secret_key_v2' => '',
                    // 必填-v3 商户秘钥
                    // 即 API v3 密钥(32字节，形如md5值)，可在 账户中心->API安全 中设置
                    'mch_secret_key' => 'EWPgObXhrWMtseGiLmX7DyDjwfvXPosk',
                    // 必填-商户私钥 字符串或路径
                    // 即 API证书 PRIVATE KEY，可在 账户中心->API安全->申请API证书 里获得
                    // 文件名形如：apiclient_key.pem
                    'mch_secret_cert' => root_path().'/config/cert/apiclient_key.pem',
                    // 必填-商户公钥证书路径
                    // 即 API证书 CERTIFICATE，可在 账户中心->API安全->申请API证书 里获得
                    // 文件名形如：apiclient_cert.pem
                    'mch_public_cert_path' => root_path().'/config/cert/apiclient_cert.pem',
                    // 必填-微信回调url
                    // 不能有参数，如?号，空格等，否则会无法正确回调
                    'notify_url' => 'https://yansongda.cn/wechat/notify',
                    // 选填-公众号 的 app_id
                    // 可在 mp.weixin.qq.com 设置与开发->基本配置->开发者ID(AppID) 查看
                    'mp_app_id' => 'wxfe7aaa8df46cf87e',
                    // 选填-小程序 的 app_id
                    'mini_app_id' => '',
                    // 选填-app 的 app_id
                    'app_id' => '',
                    // 选填-合单 app_id
                    'combine_app_id' => '',
                    // 选填-合单商户号
                    'combine_mch_id' => '',
                    // 选填-服务商模式下，子公众号 的 app_id
                    'sub_mp_app_id' => '',
                    // 选填-服务商模式下，子 app 的 app_id
                    'sub_app_id' => '',
                    // 选填-服务商模式下，子小程序 的 app_id
                    'sub_mini_app_id' => '',
                    // 选填-服务商模式下，子商户id
                    'sub_mch_id' => '',
                    // 选填-微信平台公钥证书路径, optional，强烈建议 php-fpm 模式下配置此参数
                    'wechat_public_cert_path' => [
                        '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatPublicKey.crt',
                    ],
                    // 选填-默认为正常模式。可选为： MODE_NORMAL, MODE_SERVICE
                    'mode' => Pay::MODE_NORMAL,
                ]
            ],
            'unipay' => [
                'default' => [
                    // 必填-商户号
                    'mch_id' => '777290058167151',
                    // 必填-商户公私钥
                    'mch_cert_path' => __DIR__.'/Cert/unipayAppCert.pfx',
                    // 必填-商户公私钥密码
                    'mch_cert_password' => '000000',
                    // 必填-银联公钥证书路径
                    'unipay_public_cert_path' => __DIR__.'/Cert/unipayCertPublicKey.cer',
                    // 必填
                    'return_url' => 'https://yansongda.cn/unipay/return',
                    // 必填
                    'notify_url' => 'https://yansongda.cn/unipay/notify',
                ],
            ],
            'logger' => [
                'enable' => false,
                'file' => './logs/pay.log',
                'level' => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
                'type' => 'single', // optional, 可选 daily.
                'max_file' => 30, // optional, 当 type 为 daily 时有效，默认 30 天
            ],
            'http' => [ // optional
                'timeout' => 5.0,
                'connect_timeout' => 5.0,
                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
            ],
        ];
        Pay::config($config);

        $order = [
            'out_batch_no' => time().'',
            'batch_name' => '倍可瑞转账批次',
            'batch_remark' => '倍可瑞转账批次备注',
            'total_amount' => 1,
            'total_num' => 1,
            'transfer_detail_list' => [
                [
                    'out_detail_no' =>'12345',
                    'transfer_amount' => 1,
                    'transfer_remark' => '提现',
                    'openid' => 'orl8o6vZgyooHBQ4m3bX4a-7dViA',

                    // 'user_name' => '闫嵩达'  // 明文传参即可，sdk 会自动加密
                ],
            ],
        ];

        $result = Pay::wechat()->transfer($order);
        halt($result);
    }















}
